﻿/**
 *
 * @title: Basic MVC Framework, Model Class
 * @author: Shiv
 * @license: 
 * @updated: 29/07/2010
 *
 * @version	1.0 
 */

package com.mediagallary.utils
{
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.events.EventDispatcher;
	
	import com.mediagallary.utils.XmlloaderEvent;
	
	public class  Xmlloader extends EventDispatcher
	{
		private var XmlLoader:URLLoader = new URLLoader();
		private var XMLPath:String;
		private var XMLData:XML;
		
		public function Xmlloader()
		{
			
		}
		
		public function loadXml(path:String):void
		{
			XMLPath = path;
			//trace("XMLPath ::>"+XMLPath)
			XmlLoader.addEventListener(Event.COMPLETE, parseXML);
			XmlLoader.addEventListener(IOErrorEvent.IO_ERROR, IOErrorHandler)
			XmlLoader.addEventListener(ProgressEvent.PROGRESS,ProgressEventHandler)
			
			XmlLoader.load(new URLRequest(XMLPath));
			
		}
		
		private function IOErrorHandler(event:IOErrorEvent)
		{
			//trace("IOErrorHandler :>"+event)
		}
		private function ProgressEventHandler(event:ProgressEvent)
		{
			//trace("ProgressEventHandler :>"+event)
		}
				
		public function parseXML(e:Event)
		{
			XMLData = new XML(e.target.data);
			var loadEvent:XmlloaderEvent = new XmlloaderEvent(XmlloaderEvent.COMPLETED, XMLData);
			dispatchEvent(loadEvent);
			//trace( "XMLData : " + XMLData );
		}

	}
	
}